﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ValidationFramework.Web.MVC.Tests.Fakes;
using Rhino.Mocks;

namespace ValidationFramework.Web.MVC.Tests
{
	[TestFixture]
	public class RuleConverterTests
	{
		[Test]
		public void Should_Use_Provided_Function_Call_In_Resulting_ClientRule()
		{
			// Arrange
			var ruleinfo = new RuleInfo("TestMember", new Rule(new FakeValidator()) { ErrorMessage = "Fake Message" });
			var provider = MockRepository.GenerateStub<IClientFunctionCallProvider>();
			provider.Stub(x => x.GetClientFunctionCall(null))
				.Return(new ClientFunctionCall() { FunctionName = "Foo" })
				.IgnoreArguments();

			var providerDictionary = new ClFunctionCallProviderDictionary();
			providerDictionary.Add(typeof(FakeValidator).TypeHandle, provider);

			// Act
			var converter = new RuleConverter(providerDictionary);
			var result = converter.ConvertToClientRule(ruleinfo);

			// Assert
			Assert.AreEqual(provider.GetClientFunctionCall(null), result.ClientFunctionCall);
			Assert.AreEqual("Fake Message", result.ErrorMessage);
		}

		[Test]
		public void Should_Not_Translate_Rules_For_Validators_Lacking_A_Provider()
		{
			// Arrange
			var info = new RuleInfo("TestMember", new Rule(new FakeValidator()));

			// Act
			var converter = new RuleConverter();
			var result = converter.ConvertToClientRule(info);

			// Assert
			Assert.IsNull(result);
		}



	}
}
